import { getAreaObj } from '@/utils/util'

const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ type: 'selection', reserveSelection: true },
		{ label: '所属区域', prop: 'areas_name' },
		{ label: '机构名称', prop: 'organizationName' },
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
		},
		{ label: '联系人', prop: 'burdenUserName' },
		{ label: '联系方式', prop: 'burdenUserPhone' },
		{
			label: '机构类型',
			prop: 'organizationTypeLabel',
		},
		{
			label: '机构评定星级',
			prop: 'organizationLevel',
			code: 'ORG_LEVEL',
			custome: 'dict',
		},
		{
			label: '是否备案',
			prop: 'filingFlag',
			custome: 'tag',
			dicData: [
				{ label: '否', value: 0 },
				{ label: '是', value: 1 },
			],
		},
		{
			label: '床位总数',
			prop: 'bedTotalNum',
		},
		{
			label: '收住老人',
			prop: 'refugeTotalOldmanNum',
		},
		{
			label: '操作',
			prop: 'menu',
			fixed: 'right',
      width:300
		},
	],
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '信用代码',
			prop: 'creditCode',
			type: 'input',
			span: 6,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系人',
			prop: 'burdenUserName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系方式',
			prop: 'burdenUserPhone',
			type: 'input',
			span: 6,
		},
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			changeField: true,
			span: 6,
		},
		{
			label: '机构类型',
			prop: 'organizationType',
			propName: 'organizationTypeLabel',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
		{
			label: '机构星级',
			prop: 'organizationLevel',
			propName: 'organizationLevelLabel',
			type: 'select',
			changeField: true,
			dicData: [
				{ label: '一级', value: 1 },
				{ label: '二级', value: 2 },
				{ label: '三级', value: 3 },
				{ label: '四级', value: 4 },
				{ label: '五级', value: 5 },
			],
			span: 6,
		},
		{
			label: '运营状态',
			prop: 'operateStatus',
			propName: 'operateStatusLabel',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
	],
}

export const baseConfig = {
	pageName: '养老服务组织管理',
	dictcodes: [
		'ORG_TYPE',
		'ORG_LEVEL',
		'ORG_OPERATE_STATUS',
		'ID_CARD_TYPE',
		'LEGAL_PROPERTY',
		'MEDICAL_MODE',
		'MEDICAL_INSTITUTE',
		'MEDICAL_COOPERATE_TYPE',
		'MEDICAL_INSURE_NETWORK_MODE',
		'MEDICAL_INSURE_LEVEL',
		'MEDICAL_INSURE_PROPERTY',
		'SERVICE_ITEM_TYPE',
		'NURSE_LEVEL',
		'OLDMAN_TYPE',
		'LAND_PROPERTY',
		'HOUSE_PROPERTY',
		'HOUSE_PROVE_STATUS',
		'OLDMAN_PRODUCT_TYPE',
		'DEVICE_TYPE',
	],
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'organizationName',
	api: {
		index: 'view_dpServiceOrgBase_page',
	},
	auth: {
		index: 'view_dpServiceOrgBase_page',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'sys_role_edit',
			text: true,
			show: true,
		},
	],
	paramsObj: {
		isFilterProvider: 1,
	},
	dialogConfig: {
		width: '90%',
		// fullscreen: true
	},
	searchConfig,
	beforeOnLoadFormate: async (params) => {
		const areasObj: any = getAreaObj(params.areas, '')
		return Promise.resolve({
			...params,
			...areasObj,
			areas: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasObj: any = getAreaObj(item, '', 'set')
			return {
				...item,
				areas_name: areasObj.names,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	tableConfig,
}
